package factura.util;

import java.io.File;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

public class FacturaFileChooser {
	public static JFileChooser obtenerFileChooserTxt() {
		JDialog jd = new JDialog();
		JFileChooser jfc = new JFileChooser();
		jfc.setFileFilter(new FileFilter() {
			public boolean accept(File f) {
				return (f.isDirectory()) || (f.getName().endsWith(".txt"));
			}

			public String getDescription() {
				return "text files (*.txt)";
			}
		});
		jfc.showOpenDialog(jd);
		return jfc;
	}

	public static JFileChooser obtenerFileChooserImg() {
		JDialog dialogoImagen = new JDialog();
		JFileChooser jfc = new JFileChooser();
		jfc.setFileSelectionMode(0);
		jfc.setAcceptAllFileFilterUsed(false);
		jfc.setFileFilter(new FileFilter() {
			public boolean accept(File file) {
				String fileName = file.getName().toUpperCase();
				if ((file.isDirectory()) || (fileName.endsWith(".GIF"))
						|| (fileName.endsWith(".JPEG"))
						|| (fileName.endsWith(".JPG"))
						|| (fileName.endsWith(".PNG"))) {
					return true;
				}
				return false;
			}

			public String getDescription() {
				return "Image file (*.GIF, *.JPEG, *.jpg, *.png)";
			}
		});
		jfc.showOpenDialog(dialogoImagen);
		return jfc;
	}

	public static JFileChooser obtenerFileChooserDirectorios() {
		JDialog jd = new JDialog();
		JFileChooser jfc = new JFileChooser();
		jfc.setFileSelectionMode(1);
		jfc.showOpenDialog(jd);
		return jfc;
	}
}